//
//  XGSmallVideoCollectionViewCell.swift
//  TodayNews
//
//  Created by monkey on 2020/4/5.
//  Copyright © 2020 itcast. All rights reserved.
//

import UIKit
import Kingfisher

class XGSmallVideoCollectionViewCell: UICollectionViewCell, XGRegisterReusableViewProtocol
{
    var smallVideoModel: XGSmallVideoModel? {
        didSet {
            titleLabel.text = smallVideoModel?.caption
            playCountLabel.text = (smallVideoModel?.view_count ?? 0).countString + "次播放"
            diggCountLabel.text = (smallVideoModel?.like_count ?? 0).countString + "人喜欢"
            if let url = smallVideoModel?.avatarUrls?.first?.url {
                backgroundImageView.kf.setImage(with: URL(string: url), options: [])
            }
        }
    }
    
    override init(frame: CGRect)
    {
        super.init(frame: frame)
        setUpUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - 私有属性
    
    /// 背景
    private lazy var backgroundImageView = UIImageView()
    /// 标题
    private lazy var titleLabel = UILabel(text: "测试", textColor: UIColor.orange, fontSize: 17, textAlignment: .left)
    /// 播放数量
    private lazy var playCountLabel = UILabel(text: "测试", textColor: UIColor.orange, fontSize: 15, textAlignment: .left)
    /// 点赞数
    private lazy var diggCountLabel = UILabel(text: "测试", textColor: UIColor.orange, fontSize: 15, textAlignment: .left)
}

// MARK: - 私有扩展

private extension XGSmallVideoCollectionViewCell
{
    func setUpUI() -> Void
    {
        backgroundImageView.contentMode = .scaleAspectFill
        backgroundImageView.clipsToBounds = true
        
        contentView.addSubview(backgroundImageView)
        contentView.addSubview(titleLabel)
        contentView.addSubview(playCountLabel)
        contentView.addSubview(diggCountLabel)
        
        backgroundImageView.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
        diggCountLabel.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(10)
            make.right.equalToSuperview().offset(-10)
            make.bottom.equalToSuperview().offset(-10)
        }
        playCountLabel.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(10)
            make.right.equalToSuperview().offset(-10)
            make.bottom.equalTo(diggCountLabel.snp.top).offset(-5)
        }
        titleLabel.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(10)
            make.right.equalToSuperview().offset(-10)
            make.bottom.equalTo(playCountLabel.snp.top).offset(-5)
            make.height.lessThanOrEqualTo(42)
        }
    }
}
